const app = getApp();
Page({
  data: {
    phone: "15681379520",
    description: "",
    address: "万达广场几号几栋",
    showPhone: true,
    showAddress: true,
    fileList: [],
    showModal: false,
    bgImg: app.getImgUrl("bg3.webp"),
    cameraImg: app.getImgUrl("Camera.png"),
  },

  onBack() {
    wx.navigateBack();
  },

  phonePreviewTap() {
    console.log("phonePreviewTap");
    this.setData({
      showPhone: false,
    });
  },

  addressPreviewTap() {
    this.setData({
      showAddress: false,
    });
  },

  onPhoneBlur() {
    this.setData({
      showPhone: true,
    });
  },

  onAddressBlur() {
    this.setData({
      showAddress: true,
    });
  },

  /**
   * 位置选择
   */
  onLocationTap() {
    console.log("onLocationTap");
    wx.chooseLocation({
      success: (res) => {
        const { address } = res;
        this.setData({
          address: address,
        });
        // 可将数据绑定到页面或提交服务器
      },
      fail: (err) => {
        console.error("选择失败:", err); // 常见错误：用户取消操作/权限未开启
      },
    });
  },

  /**
   * 确认提交
   */
  onConfirm() {
    console.log("onConfirm");

    this.setData({
      showModal: true,
    });
  },

  onClose() {
    this.setData({
      showModal: false,
    });
  },

  /**
   * 弹窗同意授权
   */
  onOk() {
    this.setData({
      showModal: false,
    });
  },

  afterRead(event) {
    const { file } = event.detail;
    console.log("afterRead", file);

    const { fileList = [] } = this.data;
    // @ts-ignore
    fileList.push({ ...file });
    this.setData({ fileList });
    this.setData({
      fileList,
    });
  },
});
